import { createPinia } from 'pinia';
import { createStoragePrefixName } from './utils';
import { createPersistPlugin } from 'pinia-persistence';

export const initPinia = (pkgJson, defaultStorage?) => {
  const pinia = createPinia();
  pinia.use(createPersistPlugin({ defaultStorage, namespace: createStoragePrefixName(pkgJson) + 'STORE' }));
  return pinia;
};

export function cleanPiniaStorage (pkgJson, defaultStorage?) {
  defaultStorage = defaultStorage || localStorage;
  defaultStorage.removeItem(createStoragePrefixName(pkgJson) + 'STORE' );
}
